<template>
  <a-modal
    :title="title"
    :width="modalWidth"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleOk"
    :destroyOnClose="destoryClose"
    @cancel="handleCancel"
    cancelText="关闭">
    <a-card :bordered="false">

      <!-- 查询区域 -->
      <div class="table-page-search-wrapper">
      </div>
      <!-- 操作按钮区域 -->
      <!-- table区域-begin -->
      <div>
        <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
          <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{
          selectedRowKeys.length }}</a>项
          <a style="margin-left: 24px" @click="onClearSelected">清空</a>
        </div>

        <a-table
          ref="table"
          size="middle"
          bordered
          rowKey="id"
          :columns="columns"
          :dataSource="dataSource"
          :pagination="ipagination"
          :loading="loading"
          :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange,type: rowSelectType}"
          @change="handleTableChange"
          :customRow="rowFun"
        >
          <template slot="outNum" slot-scope="text, record">
            <editable-cell :text="text" @change="onCellChange(record, 'outNum', $event)" />
          </template>
        </a-table>
      </div>
    </a-card>
  </a-modal>
</template>

<script>
  import { JeecgListMixin } from '@lone/lone-vue/src/mixins/JeecgListMixin'
  import { getAction} from '@lone/lone-vue/src/api/manage'
  import EditableCell from './EditableCell'

  export default {
    name: "MmsOutStorageModal",
    mixins: [JeecgListMixin],
    components: {
      EditableCell
    },
    data () {
      return {
        title:"可退货明细",
        dataSource:[],
        destoryClose:true,
        num:'',
        //下标
        index:-1,
        visible: false,
        modalWidth:800,
        confirmLoading: false,
        rowSelectType:'checkbox',
        description: '可退货明细',
        // 表头
        columns: [
          {
            title: '#',
            dataIndex: '',
            key:'rowIndex',
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
            title:'物资编码',
            align:"center",
            dataIndex: 'code'
          },
          {
            title:'物资名称',
            align:"center",
            dataIndex: 'name'
          },
          {
            title:'规格',
            align:"center",
            dataIndex: 'specs'
          },
          {
            title:'型号',
            align:"center",
            dataIndex: 'model'
          },
          {
            title:'计量单位',
            align:"center",
            dataIndex: 'unit'
          },
          {
            title:'入库数量',
            align:"center",
            dataIndex: 'inNum'
          },
          {
            title:'入库批次',
            align:"center",
            dataIndex: 'batch'
          },{
            title:'退货数量',
            align:"center",
            dataIndex: 'outNum',
            scopedSlots: { customRender: 'outNum' },
          }],
        url: {
          list: '/cg/mmsWzPurchaseReceive/receivePageList'
        }
      }
    },
    created () {
    },
    methods: {
      showInfo(qualityId, num,selectedRowKeys){
        this.queryParam.qualityId = qualityId;
        this.num = num
        if(selectedRowKeys  !=''){
          this.selectedRowKeys = []
          this.selectedRowKeys.push(selectedRowKeys)
        }
        this.loadData(1);
        this.visible = true
      },
      handleOk(){
        if(this.index>=0){
          this.$emit("ok",this.selectionRows,this.index);
        }else{
          this.$emit("ok",this.selectionRows,this.num);

        }
        this.handleCancel();
      },
      handleCancel () {
        this.close()
      },
      close () {
        this.$emit('close');
        this.visible = false;
        this.index = 0
      },
      rowFun (record, index) {
        return {
          on: {
            dblclick: () => {
              this.$emit("ok",record,this.index)
              this.close()
            }
          }
        }
      }
    }
  }
</script>

<style lang="less" scoped>

</style>